package com.cmsz.paydemo.util;

import java.io.IOException;

public class HttpClientUtil {
	public static String sendRequest(String url,String requestData) throws Exception {
		//模拟服务器验签
		Boolean signFlag = SignUtil.checkSign(requestData);
		System.out.println("支付平台端验签结果："+signFlag);
		String rspData = null;
		if("pay".equals(url)){
			//模拟生成支付请求的返回报文
			rspData = FileUtil.getData("payRspSynData.xml");
		}else if("query".equals(url)){
			//模拟生成查询订单的返回报文
			rspData = FileUtil.getData("queryRspData.xml");
		}else if("refund".equals(url)){
			//模拟生成退款的返回报文
			rspData = FileUtil.getData("refundRspData.xml");
		}
		//返回报文签名操作
		rspData = SignUtil.sign(rspData);
		return rspData;
	}
	
	public static String sendRequest(String url,String requestData, NotificationProcessor notificationProcessor) throws Exception {
		// init noitfication processor
		notificationProcessor.processNotification();
		String rtData = sendRequest(url,requestData);
		
		return rtData;
	}
	
	public static interface NotificationProcessor  {
		void processNotification() throws IOException;
	}
}
